﻿-- View: "V_GTIN_HF_STOCK_POLICY_HELPER"

-- DROP VIEW "V_GTIN_HF_STOCK_POLICY_HELPER";

CREATE OR REPLACE VIEW "V_GTIN_HF_STOCK_POLICY_HELPER" AS 
 SELECT DISTINCT i."NAME",
    hfb."HEALTH_FACILITY_CODE",
    sum(hfb."SAFETY_STOCK") AS sum
   FROM "ITEM" i
     LEFT JOIN "ITEM_MANUFACTURER" im ON i."ID" = im."ITEM_ID"
     LEFT JOIN "GTIN_HF_STOCK_POLICY" hfb ON hfb."GTIN" = im."GTIN"
  WHERE im."IS_ACTIVE" = true AND hfb."HEALTH_FACILITY_CODE" = 'urn:uuid:0300B088-30A2-3D6C-A30B-F692DF7F6EA1'::text
  GROUP BY i."NAME", hfb."HEALTH_FACILITY_CODE";

ALTER TABLE "V_GTIN_HF_STOCK_POLICY_HELPER"
  OWNER TO giis;
